Macromedia Flex Article

Learning Flex Basics (Part 1): Creating Your First Flex Application


Table of Contents

  1. Introduction
  2. A Brief Overview of Macromedia Flex
  3. Building the Application
  4. Create the Application Object
  5. Add a Panel for the Application Layout
  6. Add a Label for the View Header
  7. Add an Array of Objects to Define the Coffee Blends
  8. Add a ComboBox to Display the Coffee Blends
  9. Add a Text Control to Display the Description
  10. Add a Button to Add a Coffee Blend to the Shopping Cart
  11. Add a List Control for the Shopping Cart
  12. Add a Script to Handle the Button Click Event
  13. Complete Code Listing for firstapp.mxml
  14. Where to Go From Here

Add a ComboBox to Display the Coffee Blends

The Flex ComboBox is similar to an HTML select control, though more robust. The dataProvider property sets the items to display in an array of simple values or objects. You can create the array directly within a dataProvider block, but a more common approach is to create or import the data elsewhere and bind it to the dataProvider property:

<mx:ComboBox id="myCombo" dataProvider="{myArray}"/>

The curly braces signal the compiler that what's inside is an expression or variable to evaluate rather than a literal string.

If the objects contain label and data properties, these are used automatically for the displayed items and data associated with them—the data can be a scalar value or complex type such as an object. If the objects do not have label and data properties, then the entire objects are used for the item data properties, and the label value is set to one of the object properties using the labelField property of the ComboBox.

  1. Add a ComboBox control after the Label, giving an id of coffeeCombo and using the dataProvider property to bind the ComboBox to the coffeeArray you created in the previous step:

    <mx:ComboBox id="coffeeCombo" dataProvider="{coffeeArray}"/>